package jspservlet.servlet;

import java.io.IOException;
//import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import jspservlet.dao.InfoDAO;
import jspservlet.dao.UserDAO;
//import jspservlet.dao.impl.InfoDAOImpl;
import jspservlet.dao.impl.UserDAOImpl;
import jspservlet.vo.Device;
public class RegisDeviceServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		Device device=new Device();
		//PrintWriter out = res.getWriter();
		device.setDeviceid(req.getParameter("deviceid"));
		device.setFamilyid(req.getParameter("familyid"));
        device.setShanchu(0);
		UserDAO dao = new UserDAOImpl(); 
		int flag = 0;
		
			try {
				flag = dao.registeDevice(device);
			} 
			catch (Exception e) {
				e.printStackTrace();
			}
			if(flag == 1){
				res.getWriter().println("<script>alert('Registration Successful!')</script>");
				res.getWriter().println("<script>window.location.href='./index.jsp'</script>");
			}else{
				res.getWriter().println("<script>alert('Registration Failed!')</script>");
				res.getWriter().println("<script>window.location.href='./register.jsp'</script>");
			
		}
}